package com.huli.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huli.mapper.MaterialMapper;
import com.huli.pojo.SysMaterial;
import com.huli.service.MaterialService;
import com.huli.vo.OrganizationUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MaterialServiceImpl implements MaterialService {
    @Autowired
    private MaterialMapper materialMapper;
    @Override
    public List<SysMaterial> materialList() {
        return materialMapper.materialList();
    }

    @Override
    public OrganizationUserVo materialList1(OrganizationUserVo param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<SysMaterial> sysMaterials = materialMapper.materialList1();
        PageInfo<SysMaterial> sysMaterialPageInfo = new PageInfo<>(sysMaterials);
        return new OrganizationUserVo(sysMaterialPageInfo.getTotal(),sysMaterialPageInfo.getList());
    }

    @Override
    public void deleteMaterial(Long id) {
        materialMapper.deleteMaterial(id);
    }

    @Override
    public void updateMaterial(SysMaterial sysMaterial) {
        sysMaterial.setUpdateTime(new Date());
        materialMapper.updateMaterial(sysMaterial);
    }

    @Override
    public void addMaterial(SysMaterial sysMaterial) {
        sysMaterial.setUpdateTime(new Date());
        sysMaterial.setCreateTime(new Date());
        materialMapper.addMaterial(sysMaterial);
    }

    @Override
    public SysMaterial selectMaterialById(Long id) {
        SysMaterial sysMaterial = materialMapper.selectMaterialById(id);
        return sysMaterial;
    }

    @Override
    public List<SysMaterial> materialByMaterialName(String materialName) {
        List<SysMaterial> sysMaterial = materialMapper.materialByMaterialName(materialName);
        return sysMaterial;
    }

    @Override
    public List<SysMaterial> findAll() {
        List<SysMaterial> all = materialMapper.findAll();
        return all;
    }
}
